home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_6 / diffnew.m < prev   
Encoding:
Text File  |  1994-06-05  |  593 b   |  25 lines  |  [MATF/MATL]

  1. function [A,df] = diffnew(X,Y)
  2. % [A,df] = diffnew(X,Y)
  3. % Numerical approximation for f'(x).
  4. % The method is differentiation of the Newton polynomial Pn(x).
  5. % An approximation for  f'(X(1))  is computed.
  6. % X  is the list of abscissas, input.
  7. % Y  is the list of abscissas, input.
  8. % A  is the coefficient list for  Pn(x), output.
  9. % df is the approximate derivative, output.
  10. A = Y;
  11. n = length(X);
  12. for j=2:n,
  13.   for k=n:-1:j,
  14.       A(k) = (A(k)-A(k-1))/(X(k)-X(k-j+1));
  15.   end
  16. end
  17. x0 = X(1);
  18. df = A(2);
  19. prod = 1;
  20. n1 = length(A)-1;
  21. for k=2:n1,
  22.   prod = prod*(x0 - X(k));
  23.   df = df + prod*A(k+1);
  24. end
  25.